package com.ahjz.ahjzdemo.adapter;

import java.util.List;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ahjz.ahjzdemo.R;
import com.ahjz.ahjzdemo.model.RemoteData;

public class ListViewAdapter extends BaseAdapter {
	public List<RemoteData> dataList;
	private LayoutInflater layoutInflater;

	public ListViewAdapter(Context context, List<RemoteData> dataList) {
		this.dataList = dataList;
		this.layoutInflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return dataList.size();
	}

	@Override
	public Object getItem(int position) {
		return dataList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = layoutInflater.inflate(R.layout.list_item, null);
		}
		ImageView imageView = (ImageView) convertView
				.findViewById(R.id.imageview);
		TextView textView = (TextView) convertView.findViewById(R.id.textview);

		RemoteData data = dataList.get(position);

		imageView.setBackgroundColor(data.color);
		Log.d("Color", "setBackgroundColor: " + data.color +"  >>  "+ data.number);
		textView.setText(data.name + "     " + data.number);

		return convertView;
	}
}
